﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CastleDemo1.Model;
namespace CastleDemo1
{
    public partial class CommentList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["Action"] != null && Request.QueryString["Action"] == "Query" && Request.QueryString["PostId"] !=null)
                {
                   rep1.DataSource=GetCommentData(Request.QueryString["PostId"]);
                   rep1.DataBind();
                }
            }
        }

        private IList<Comment> GetCommentData(string postId)
        {
            if (string.IsNullOrEmpty(postId))
            {
                throw new ArgumentNullException("PostId");
            }
            Post post=  Post.Find(new Guid(postId));
            if(post!=null)
            {
                return Comment.FindAllByProperty("Post",post).ToList();
            }
            return new List<Comment>();            
        }
    }
}